package com.lzh.healthCode.business.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lzh.healthCode.business.entity.*;
import com.lzh.healthCode.core.BaseConfig;
import com.lzh.healthCode.utils.UpdAreaEnum;
import com.lzh.healthCode.utils.UpdTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author suYanLong
 * @date 2022年07月22日 16:12
 */
@Slf4j
@Component
public class CommonService extends BaseConfig {

    @Resource
    CjInfoService cjInfoService;
    @Resource
    ZyInfoService zyInfoService;
    @Resource
    JgInfoService jgInfoService;

    public void uploadSampleReport(UpdAreaEnum updAreaEnum, UpdTypeEnum updTypeEnum, CjInfoBean cjInfoBean) {
        try {

            // 测试人员信息上传接口 【参数】
            String fxrzjhm;
            JSONArray jsonArray = new JSONArray();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("bjcrxm", cjInfoBean.getBJCRXM());
            jsonObject.put("bjcrjzdzds", cjInfoBean.getBJCRJZDZDS());
            jsonObject.put("bjcrjzdzqx", cjInfoBean.getBJCRJZDZQX());
            jsonObject.put("bjcrjzdzxxdz", cjInfoBean.getBJCRJZDZXXDZ());
            jsonObject.put("bjcrzjlx", cjInfoBean.getBJCRZJLX());
            jsonObject.put("bjcrzjhm", cjInfoBean.getBJCRZJHM());
            jsonObject.put("bjcrsjh", cjInfoBean.getBJCRSJH());
            jsonObject.put("sgxbm", cjInfoBean.getSGXBM());
            jsonObject.put("cyfs", cjInfoBean.getCYFS());
            jsonObject.put("hjlx", cjInfoBean.getHJLX());
            jsonObject.put("sgbm", cjInfoBean.getSGBM());
            jsonObject.put("cyddmc", cjInfoBean.getCYDDMC());
            jsonObject.put("cyddssds", cjInfoBean.getCYDDSSDS());
            jsonObject.put("cyddssqx", cjInfoBean.getCYDDSSQX());
            jsonObject.put("cyddfkdj", cjInfoBean.getCYDDFKDJ());
            jsonObject.put("ybly", cjInfoBean.getYBLY());
            jsonObject.put("cyrxm", cjInfoBean.getCYRXM());
            jsonObject.put("cyrzjlx", cjInfoBean.getCYRZJLX());
            jsonObject.put("cyrzjhm", cjInfoBean.getCYRZJHM());
            jsonObject.put("cyrssdw", cjInfoBean.getCYRSSDW());
            jsonObject.put("cyrsjhm", cjInfoBean.getCYRSJHM());
            jsonObject.put("bblx", cjInfoBean.getBBLX());
            jsonObject.put("hsjclx", cjInfoBean.getHSJCLX());
            jsonObject.put("hsjclxhyzy", cjInfoBean.getHSJCLXHYZY());
            jsonObject.put("cysj", cjInfoBean.getCYSJ());
            jsonObject.put("tbrxm", cjInfoBean.getTBRXM());
            jsonObject.put("tbrsjh", cjInfoBean.getTBRSJH());
            jsonObject.put("tbrzjlx", cjInfoBean.getTBRZJLX());
            jsonObject.put("tbrzjhm", cjInfoBean.getTBRZJHM());
            jsonObject.put("tbrssds", cjInfoBean.getTBRSSDS());
            jsonObject.put("tbrssqx", cjInfoBean.getTBRSSQX());
            jsonObject.put("tbrssdw", cjInfoBean.getTBRSSDW());
            jsonObject.put("fxrxm", cjInfoBean.getFXRXM());
            jsonObject.put("fxrsjh", cjInfoBean.getFXRSJH());
            jsonObject.put("fxrzjlx", cjInfoBean.getFXRZJLX());
            jsonObject.put("fxrzjhm", cjInfoBean.getFXRZJHM());
//            jsonObject.put("fxrzjhm", "");
            jsonObject.put("fxrssdw", cjInfoBean.getFXRSSDW());
            jsonObject.put("fxsj", cjInfoBean.getFXSJ());
            jsonObject.put("sfqk", cjInfoBean.getSFQK());
            jsonArray.add(jsonObject);
            // 测试人员信息上传接口 【参数】【加密】
            ResultBean resultBean = null;
            if (UpdAreaEnum.UPD_AREA_TYPE_1.equals(updAreaEnum)) {
                resultBean = httpRequestConfig.sendPost(healthCodeInfo.getSampleReportUrl(), jsonArray.toJSONString());
            } else if (UpdAreaEnum.UPD_AREA_TYPE_2.equals(updAreaEnum)) {
                resultBean = httpRequestConfig.sendPostProvince(healthCodeInfo.getSampleReportUrl(), jsonArray.toJSONString());
            }

            JSONObject result = JSONObject.parseObject(resultBean.getResult());
            String errorCount = result.getString("errorCount");
            String feedBackList = result.getString("feedbackList");
            String sampleno = cjInfoBean.getSAMPLENO();
            UpdParams updParams = new UpdParams(errorCount, feedBackList, sampleno, updAreaEnum, updTypeEnum);
            cjInfoService.updateErrorCount(updParams);
        } catch (Exception exception) {
            log.error("uploadSampleReport发生异常：", exception);
            exception.printStackTrace();
        }

    }



    public void uploadtransportReport(UpdAreaEnum updAreaEnum, UpdTypeEnum updTypeEnum, ZyInfoBean zyInfoBean) {
        try {
            // 测试人员信息上传接口 【参数】
            JSONArray jsonArray = new JSONArray();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("sgbm", zyInfoBean.getSGBM());
            jsonObject.put("sgxbm", zyInfoBean.getSGXBM());
            jsonObject.put("zyrxm", zyInfoBean.getZYRXM());
            jsonObject.put("zyrzjlx", zyInfoBean.getZYRZJLX());
            jsonObject.put("zyrzjhm", zyInfoBean.getZYRZJHM());
            jsonObject.put("zyrssdw", zyInfoBean.getZYRSSDW());
            jsonObject.put("zyrsjhm", zyInfoBean.getZYRSJHM());
            jsonObject.put("qysj", zyInfoBean.getQYSJ());
            jsonObject.put("jssj", zyInfoBean.getJSSJ());
            jsonObject.put("jsrxm", zyInfoBean.getJSRXM());
            jsonObject.put("jsrlxfs", zyInfoBean.getJSRLXFS());
            jsonObject.put("jsrzjlx", zyInfoBean.getJSRZJLX());
            jsonObject.put("jsrzjhm", zyInfoBean.getJSRZJHM());
            jsonObject.put("jsjgmc", zyInfoBean.getJSJGMC());
            jsonObject.put("jsjgssds", zyInfoBean.getJSJGSSDS());
            jsonObject.put("jsjgssqx", zyInfoBean.getJSJGSSQX());
            jsonArray.add(jsonObject);
            // 测试人员信息上传接口 【参数】【加密】
            ResultBean resultBean = null;
            if (UpdAreaEnum.UPD_AREA_TYPE_1.equals(updAreaEnum)) {
                resultBean = httpRequestConfig.sendPost(healthCodeInfo.getTransportReportUrl(), jsonArray.toJSONString());
            } else if (UpdAreaEnum.UPD_AREA_TYPE_2.equals(updAreaEnum)) {
                resultBean = httpRequestConfig.sendPostProvince(healthCodeInfo.getTransportReportUrl(), jsonArray.toJSONString());
            }
            JSONObject result = JSONObject.parseObject(resultBean.getResult());
            String errorCount = result.getString("errorCount");
            String feedBackList = result.getString("feedbackList");
            String sampleno = zyInfoBean.getSAMPLENO();
            UpdParams updParams = new UpdParams(errorCount, feedBackList, sampleno, updAreaEnum, updTypeEnum);
            zyInfoService.updateErrorCount(updParams);
        } catch (Exception exception) {
            log.error("uploadSampleReport发生异常：", exception);
            exception.printStackTrace();
        }

    }




    public void uploadcheckResultReport(UpdAreaEnum updAreaEnum, UpdTypeEnum updTypeEnum, JgInfoBean jgInfoBean) {
        try {
            // 测试人员信息上传接口 【参数】
            JSONArray jsonArray = new JSONArray();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("sgbm", jgInfoBean.getSGBM());
            jsonObject.put("jckssj", jgInfoBean.getJCKSSJ());
            jsonObject.put("jcjssj", jgInfoBean.getJCJSSJ());
            jsonObject.put("jcjg", jgInfoBean.getJCJG());
            jsonObject.put("bgshsj", jgInfoBean.getBGSHSJ());
            jsonObject.put("jcjgmc", jgInfoBean.getJCJGMC());
            jsonObject.put("jcjgssds", jgInfoBean.getJCJGSSDS());
            jsonObject.put("jcjgssqx", jgInfoBean.getJCJGSSQX());
            jsonObject.put("syslx", jgInfoBean.getSYSLX());
            jsonObject.put("jcsysmc", jgInfoBean.getJCSYSMC());
            jsonObject.put("hsjccph", jgInfoBean.getHSJCCPH());
            jsonObject.put("hstqffx", jgInfoBean.getHSTQFFX());
            jsonObject.put("jcrxm", jgInfoBean.getJCRXM());
            jsonObject.put("jcrlxfs", jgInfoBean.getJCRLXFS());
            jsonObject.put("jcjgsjjhsj", jgInfoBean.getJCJGSJJHSJ());
            jsonArray.add(jsonObject);
            // 测试人员信息上传接口 【参数】【加密】
            ResultBean resultBean = null;
            if (UpdAreaEnum.UPD_AREA_TYPE_1.equals(updAreaEnum)) {
                resultBean = httpRequestConfig.sendPost(healthCodeInfo.getCheckResultReportUrl(), jsonArray.toJSONString());
            } else if (UpdAreaEnum.UPD_AREA_TYPE_2.equals(updAreaEnum)) {
                resultBean = httpRequestConfig.sendPostProvince(healthCodeInfo.getCheckResultReportUrl(), jsonArray.toJSONString());
            }
            JSONObject result = JSONObject.parseObject(resultBean.getResult());
            String errorCount = result.getString("errorCount");
            String feedBackList = result.getString("feedbackList");
            String sampleno = jgInfoBean.getSAMPLENO();
            UpdParams updParams = new UpdParams(errorCount, feedBackList, sampleno, updAreaEnum, updTypeEnum);
            jgInfoService.updateErrorCount(updParams);
        } catch (Exception exception) {
            log.error("uploadSampleReport发生异常：", exception);
            exception.printStackTrace();
        }

    }


}
